package com.v.air.app.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.v.air.app.R;
import com.v.air.app.bean.CityBean;
import com.v.air.app.interfaces.CityClickListener;

public class SettingAdapter extends BaseAdapter {
	private List<CityBean> data = new ArrayList<CityBean>();
	private LayoutInflater inflater;

	public SettingAdapter(Context context) {
		this.inflater = LayoutInflater.from(context);
	}

	public List<CityBean> getData() {
		return data;
	}

	public void setData(List<CityBean> data) {
		this.data = data;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data.get(position);
	}

	@Override
	public long getItemId(int id) {
		// TODO Auto-generated method stub
		return id;
	}

	public class ViewHolder {
		private LinearLayout layout;
		private TextView nameTextView;
		private TextView numTextView;
	}

	public View getView(final int position, View contentView, ViewGroup arg2) {
		ViewHolder holder = null;
		if (contentView == null) {
			holder = new ViewHolder();
			contentView = inflater.inflate(R.layout.setting_item, null);
			holder.layout = (LinearLayout) contentView
					.findViewById(R.id.layout);
			holder.nameTextView = (TextView) contentView
					.findViewById(R.id.name);
			holder.numTextView = (TextView) contentView
					.findViewById(R.id.number);
			contentView.setTag(holder);
		} else {
			holder = (ViewHolder) contentView.getTag();
		}
		final CityBean bean = data.get(position);
		holder.nameTextView.setTag(bean);
		holder.nameTextView.setText(bean.getName());
		holder.numTextView.setText((position + 1) + "");
		return contentView;
	}
}
